home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / sysv-rc < prev    next >
Encoding:
Text File  |  2010-11-16  |  3.4 KB  |  111 lines

  1. # update-rc.d(8) completion
  2. #
  3. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  4.  
  5. have update-rc.d &&
  6. _update_rc_d()
  7. {
  8.     local cur prev sysvdir services options valid_options
  9.  
  10.     _get_comp_words_by_ref cur prev
  11.  
  12.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  13.     || sysvdir=/etc/init.d
  14.  
  15.     services=( $(printf '%s ' $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm@(orig|new|save))) )
  16.     services=( ${services[@]#$sysvdir/} )
  17.     options=( -f -n )
  18.  
  19.     if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
  20.     valid_options=( $( \
  21.         tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \
  22.         | sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \
  23.         | sort | uniq -u \
  24.         ) )
  25.     COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
  26.         -X '$( tr " " "|" <<<${COMP_WORDS[@]} )' -- "$cur" ) )
  27.     elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]]; then
  28.         COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) )
  29.     elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
  30.         COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  31.     elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
  32.         COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  33.     elif [[ "$prev" == defaults && -z "$cur" ]]; then
  34.         COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
  35.     elif [[ "$prev" == ?(start|stop) ]]; then
  36.         if [[ "$cur" == [0-9] || -z "$cur" ]]; then
  37.             COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
  38.         elif [[ "$cur" == [0-9][0-9] ]]; then
  39.             COMPREPLY=( $cur )
  40.         else
  41.             COMPREPLY=()
  42.         fi
  43.     elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
  44.         if [[ -z "$cur" ]]; then
  45.             if [[ $prev == [0-9][0-9] ]]; then
  46.                 COMPREPLY=( 0 1 2 3 4 5 6 S )
  47.             else
  48.                 COMPREPLY=( 0 1 2 3 4 5 6 S . )
  49.             fi
  50.         elif [[ "$cur" == [0-6S.] ]]; then
  51.             COMPREPLY=( $cur )
  52.         else
  53.             COMPREPLY=()
  54.         fi
  55.     elif [[ "$prev" == "." ]]; then
  56.         COMPREPLY=( $(compgen -W "start stop" -- "$cur") )
  57.     else
  58.         COMPREPLY=()
  59.     fi
  60.  
  61.     return 0
  62. } &&
  63. complete -F _update_rc_d update-rc.d
  64.  
  65. # invoke-rc.d(8) completion
  66. #
  67. # Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
  68. #
  69. have invoke-rc.d &&
  70. _invoke_rc_d()
  71. {
  72.     local cur prev sysvdir services options valid_options
  73.  
  74.     _get_comp_words_by_ref cur prev
  75.  
  76.     [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
  77.     || sysvdir=/etc/init.d
  78.  
  79.     services=( $( printf '%s ' \
  80.         $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm@(orig|new|save)) ) )
  81.     services=( ${services[@]#$sysvdir/} )
  82.     options=( --help --quiet --force --try-anyway --disclose-deny --query \
  83.         --no-fallback )
  84.  
  85.     if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
  86.     valid_options=( $( \
  87.         tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \
  88.         | sed -ne "/$( sed "s/ /\\\\|/g" <<<"${options[@]}" )/p" \
  89.         | sort | uniq -u \
  90.         ) )
  91.     COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- "$cur" ) )
  92.     elif [ -x $sysvdir/$prev ]; then
  93.         COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
  94.             -ne "s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
  95.             $sysvdir/$prev`' -- "$cur" ) )
  96.     else
  97.         COMPREPLY=()
  98.     fi
  99.  
  100.     return 0
  101. } &&
  102. complete -F _invoke_rc_d invoke-rc.d
  103.  
  104. # Local variables:
  105. # mode: shell-script
  106. # sh-basic-offset: 4
  107. # sh-indent-comment: t
  108. # indent-tabs-mode: nil
  109. # End:
  110. # ex: ts=4 sw=4 et filetype=sh
  111.